﻿using System;
using System.Collections.Generic; 
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLPropertyGrid;
using SLPropertyGrid.Converters;

namespace FormDesigner
{
    [DataContract]
    public class HtmlLabelModel
    {
        private string text;
        private LabelType type;
        private LabelAlign align;

        private int width;
        private int location_x;
        private int location_y;

        public Label ctrl;

        public HtmlLabelModel(Label label)
        {
            this.ctrl = label;
        }

        [SLPropertyGrid.DisplayName("文本")]
        [System.ComponentModel.Description("用于描述改控件用途")]
        [DataMember]
        public string Text
        {
            get { return text; }
            set
            { 
                this.text = value;
                if (AType == LabelType.表单项)
                    this.text = this.text.Replace("\r", "");

                if (this.text == "")
                    this.text = "文本";
                if( this.ctrl !=null )
                    this.ctrl.Content = this.text;
            }
        }


        [DataMember]
        [SLPropertyGrid.DisplayName("类型")]
        [System.ComponentModel.Description("用于表示该控件类型")]
        public LabelType AType
        {
            get { return type; }
            set { type = value; }
        }

        [DataMember]
        [SLPropertyGrid.DisplayName("位置")]
        [System.ComponentModel.Description("用于表示该控件对齐方式")]
        public LabelAlign Align
        {
            get { return align; }
            set { align = value; }
        }
        [DataMember]
        [SLPropertyGrid.DisplayName("宽度")]
        [System.ComponentModel.Description("用于表示该控件宽度")]
        public int Width
        {
            get { return width; }
            set { width = value; }
        }
        [DataMember]
        [Browsable(false)]
        public int LocationX
        {
            get
            {
                return ctrl != null ? location_x = (int)Canvas.GetLeft(ctrl) : location_x;
            }
            set
            {
                 location_x = value;
                if (ctrl !=null )
                    Canvas.SetLeft(ctrl, value);
            }
        }
        [DataMember]
        [Browsable(false)]
        public int LocationY
        {
            get
            {
                return ctrl != null ? location_y = (int)Canvas.GetTop(ctrl) : location_y;
            }
            set
            {
                location_y = value;
                if (ctrl !=null )
                    Canvas.SetTop(ctrl, value);
            }
        }

    }

    //public enum LabelType
    //{
    //    文本项 = 0,
    //    复选项 = 1,
    //    单选项 = 2
    //}

    public enum LabelAlign
    {
        靠左 = 0,
        居中 = 1,
        靠右 = 2 
    }

    public enum LabelType
    {
        表单项 = 0,
        描述项 = 1
    }

}
